<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.name" placeholder="客户姓名"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getSetteds">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="handleResart">重置</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="setteds" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column prop="id" label="结算单编号" align="center" width="130" sortable>
			</el-table-column>
			<el-table-column prop="order_id" label="维修单编号" align="center" width="130" sortable>
			</el-table-column>
			<el-table-column prop="custormer" label="客户姓名" align="center" width="120" sortable>
			</el-table-column>
			<el-table-column prop="re_amount" label="应付金额" align="center" width="120" sortable>
			</el-table-column>
			<el-table-column prop="pay_amount" label="实付金额" align="center" width="120" sortable>
			</el-table-column>
            <el-table-column prop="payType.typeName" label="支付方式" align="center" min-width="150" sortable>
            </el-table-column>
            <el-table-column prop="settedTime" label="创建时间" align="center" width="180" sortable>
            </el-table-column>
			<el-table-column label="操作" align="center" width="100">
				<template scope="scope">
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">取消结算</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" align="center">
			</el-pagination>
		</el-col>

	</section>
</template>

<script>

    export default {
        data() {
            return {
                filters: {
                    name: ''
                },
                setteds: [],
                currentPage: 1,
                total: 0,
                listLoading: false,
                sels: [],//列表选中列
				updateForm:{},
                editFormVisible: false,//编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    name: [
                        { required: true, message: '请输入姓名', trigger: 'blur' }
                    ]
                },
                //编辑界面数据
                editForm: {
                    id: 0,
                    name: '',
                    sex: -1,
                    age: 0,
                    birth: '',
                    addr: ''
                },

                addFormVisible: false,//新增界面是否显示
                addLoading: false,
                addFormRules: {
                    name: [
                        { required: true, message: '请输入姓名', trigger: 'blur' }
                    ]
                },
            }
        },
        methods: {
            handleCurrentChange(val) {
                this.currentPage = val;
                this.getSetteds();
            },
            //获取用户列表
            getSetteds() {
                let para = {
                    //将当前页传到后端
                    currentPage: this.currentPage,
					//将输入的名字传到后台查询
                    name: this.filters.name
                }
                //console.debug(para);
                this.listLoading = true;
                this.$http.patch('setted/queryPage',para).then((res) => {
                    //console.debug(res);
                    this.listLoading = false;
                    this.setteds = res.data.rows;
                    this.total = res.data.total;
                });
            },
            //删除
            handleDel(index, row) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    //出现加载中效果
                    this.listLoading = true;
                    let id = row.id;
                    this.$http.delete('setted/'+id).then(res=>{
                        //去掉转圈圈效果
                        this.listLoading = false;
                        let {success,message} = res.data;
                        if(success){
                            this.$message({
                                message: message,
                                type: 'success'
                            });
                            console.log(row)
                            this.$http.post('/repairOrder/update2',row).then(res =>{
                            })
                            this.getSetteds();
                        }else {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        }
                    });
                }).catch(() => {

                });
            },
			//日期格式化
            /*dateFormat:function(row,column){
                var t=new Date(row.settedTime);//row 表示一行数据, settedTime 表示要格式化的字段名称
                return t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate()+" "+t.getHours()+":"+t.getMinutes();
            },*/
			//重置
            handleResart(){
                this.filters.name = '';
			},
            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {
                var ids = this.sels.map(item => item.id).toString();
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    let para = { ids: ids };
                    batchRemoveUser(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getUsers();
                    });
                }).catch(() => {

                });
            }
        },
        mounted() {
            this.getSetteds();
        }
    }

</script>

<style scoped>

</style>te>